package com.zero.jewelry.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zero.common.core.domain.page.PageDomain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zero.common.annotation.log.Log;
import com.zero.common.core.basecontroller.BaseController;
import com.zero.common.core.domain.result.AjaxResult;
import com.zero.common.core.enums.BusinessType;
import com.zero.jewelry.domain.Bracelet;
import com.zero.jewelry.service.IBraceletService;
import com.zero.common.core.utils.poi.ExcelUtil;
import com.zero.common.core.domain.page.TableDataInfo;

/**
 * 手镯尺码管理Controller
 * 
 * @author cai-xu-kun
 * @date 2025-08-12
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "手镯尺码管理")
@RequestMapping("/jewelry/bracelet")
public class BraceletController extends BaseController {

    private final IBraceletService braceletService;

    //根据产品ID查尺码，回显

    @ApiOperation("查询手镯尺码管理分页")
    @PreAuthorize("@ss.hasPermi('jewelry:bracelet:list')")
    @GetMapping("/product/{productId}")
    public AjaxResult getByProductId(@PathVariable Long productId) {
        LambdaQueryWrapper<Bracelet> queryWrapper = new LambdaQueryWrapper<>();//构造查询条件（带参）
        queryWrapper.eq(Bracelet::getProductId,productId);

        List<Bracelet> list = braceletService.list(queryWrapper);
        return AjaxResult.success(list);
    }

    /*============================================*/


    /**
     * 查询手镯尺码管理分页
     */
    @ApiOperation("查询手镯尺码管理分页")
    @PreAuthorize("@ss.hasPermi('jewelry:bracelet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bracelet bracelet) {
        PageDomain pageDomain = this.startPage();
        Page<Bracelet> p = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<Bracelet> page = braceletService.selectBraceletListPage(bracelet, p);
        return this.getDataTable(page);
    }

    /**
     * 导出手镯尺码管理列表
     */
    @ApiOperation("导出手镯尺码管理列表")
    @PreAuthorize("@ss.hasPermi('jewelry:bracelet:export')")
    @Log(title = "手镯尺码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bracelet bracelet) {
        List<Bracelet> list = braceletService.selectBraceletList(bracelet);
        ExcelUtil<Bracelet> util = new ExcelUtil<Bracelet>(Bracelet.class);
        util.exportExcel(response, list, "手镯尺码管理数据");
    }

    /**
     * 获取手镯尺码管理详细信息
     */
    @ApiOperation("获取手镯尺码管理详细信息")
    @PreAuthorize("@ss.hasPermi('jewelry:bracelet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(braceletService.selectBraceletById(id));
    }

    /**
     * 新增手镯尺码管理
     */
    @ApiOperation("新增手镯尺码管理")
    @PreAuthorize("@ss.hasPermi('jewelry:bracelet:add')")
    @Log(title = "手镯尺码管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bracelet bracelet) {
        return toAjax(braceletService.insertBracelet(bracelet));
    }

    /**
     * 修改手镯尺码管理
     */
    @ApiOperation("修改手镯尺码管理")
    @PreAuthorize("@ss.hasPermi('jewelry:bracelet:edit')")
    @Log(title = "手镯尺码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bracelet bracelet) {
        return toAjax(braceletService.updateBracelet(bracelet));
    }

    /**
     * 删除手镯尺码管理
     */
    @ApiOperation("删除手镯尺码管理")
    @PreAuthorize("@ss.hasPermi('jewelry:bracelet:remove')")
    @Log(title = "手镯尺码管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(braceletService.deleteBraceletByIds(ids));
    }
}
